<!DOCTYPE html>
<html
        layout:decorator="component/mainLayout"
        xmlns="http://www.w3.org/1999/xhtml"
        xmlns:th="http://www.thymeleaf.org"
        lang="en" xmlns:layout="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>公告留言</title>
</head>
<link rel="stylesheet" type="text/css" href="/layui/css/layui.css" media="all"/>
<link rel="stylesheet" type="text/css" href="/layui/css/template.css" media="all"/>
<script src="/layui/layui.js" charset="utf-8"></script>
<body layout:fragment="contentCenter">

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 28px;">
    <legend>公告留言发布</legend>
</fieldset>
    <form class="layui-form layui-form-pane" style="border: 1px solid slategray;padding: 20px 20px 0" >
        <div class="layui-form-item">
            <label class="layui-form-label">公告标题</label>
            <div class="layui-input-block">
                <input type="text" name="title" value="李欣同学明天放假"  class="layui-input">
            </div>
        </div>


        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">公告内容</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" class="layui-textarea" name="content"  value="落霞与孤鹜齐飞++秋水共长天一色++曾经沧海难为水++除却巫山不是云"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <button class="layui-btn" lay-submit="" lay-filter="demo2" style="float:right;">发布</button>
            <button type="reset" class="layui-hide">发布</button>
        </div>
    </form>
<script>
    $(document).ready(function () {
        sliderCollapse.open('#noticeCollapse');
    })

    layui.use(['form','element','layer','form'],function () {
        var $ = layui.$
            ,element = layui.element
            ,layer = layui.layer
            ,form = layui.form;

        //监听提交
        form.on('submit(demo2)', function(data){
            let notice = {
                noticeTitle:data.field.title,
                noticeContent:data.field.content
            };
            $.ajax({
                type: "POST",
                data: notice,
                url: "/notice/saveNotice",
                success: function (data) {
                    console.log(data);
                    if (data.status===200){
                        layer.alert("公告发布成功!", {icon: 1});
                        $(".layui-hide").click();
                    }else{
                        mdui.snackbar({
                            message: data.status===200?'公告发布成功':'公告发布失败',
                            buttonText: 'OK',
                            timeout:700,
                            onClose: function () {
                            }
                        });
                    }
                },
                error: function (request) {
                    mdui.snackbar({
                        message: '发布失败,未知错误',
                        buttonText: 'OK',
                    });
                }
            });
            return false;
        });
    })

</script>
</body>
</html>